{% extends "base.html" %}
{% block title %}项目组成{% endblock %}
{% block user %}项目成员{% endblock %}
{% block styles %}{{ super() }}
<style>
    .progress {
        position: relative;
        top: 0px;
        transform: translateY(50%);
        width: 80%;
    }

    .progress span {
        position: absolute;
        display: block;
        width: 100%;
        color: black;
    }

    table.dataTable tbody td {
        text-align: left;
        vertical-align: middle;
    }
</style>
{% endblock %}

{% block scripts %}{{ super() }}
<script>
    $(document).ready(function () {
        $('#dt').DataTable(
            {

                "autoWidth": true,
                "search": {
                    "regex": true
                },

                "pageLength": 25,
                "order": [[2, "desc"], [0, "asc"]],

                dom: '<"top"flipB<"clear">>rt<"bottom"ipB<"clear">>',
                buttons: [
                    'copy', 'csv', 'excel'
                ]


            });
    });

    $(function () {
        $('.planmanhour').click(function () {
            var planmanhour = parseInt($(this).siblings('input')[0].value);
            if (isNaN(planmanhour) || planmanhour < 0) {
                alert('请正确填写计划工时!');
            }
            else {
                var project_org_id = $($(this).siblings('input')[0]).data("project-org-id");
                var project_id = $($(this).siblings('input')[0]).data("project-id");
                window.location.href = "{{ url_for('bp_assess.set_plan_manhour',project_id=9999, project_org_id=8888, plan_manhour=7777) }}".replace('8888', project_org_id).replace('9999', project_id).replace('7777', planmanhour);
            }

        });
    });
</script>
{% endblock %}
{% block content %}
<div class="container">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            {% include 'flash_message.html' %}
        </div>
        {% if current_user.admin %}
        <div class="btn btn-success">
            <a href="{{ url_for('bp_assess.add_project_org', project_id=project_id) }}">添加组织架构</a>
        </div>
        {% endif %}


        <h4 class="row page-header" style="text-align:center">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                {{ project_name[0] }} {{ project_name[1] }} 项目成员列表
            </div>
        </h4>

        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <table id="dt" class="row-border hover compact table" style="width:100%">
                <thead>
                    <tr>
                        <th>id</th>
                        <th>成员姓名</th>
                        <th>是否负责人</th>
                        <th>填报比例</th>
                        <th>填报工时</th>
                        <th>计划工时</th>
                        <th>剩余工时</th>

                        {% if current_user.admin %}
                        <td>修改计划工时</td>
                        <td>修改</td>
                        <td>删除</td>
                        {% endif %}

                    </tr>
                </thead>
                <tbody>
                    {% for user in project_users %}
                    {% if user[1] %}
                    <tr class="danger">
                        {% else %}
                    <tr>

                        {% endif %}
                        <td>{{ user[0] }}</td>
                        <td><a href="{{ url_for('bp_partner.calendar', user_id=user[5]) }}">{{ user[2] }}</a></td>
                        <td>
                            {% if user[1] %}
                            是
                            {% else %}
                            否
                            {% endif %}

                        </td>

                        <!-- 比例开始 -->
                        <td>
                            {% if user[4] %}

                            {% if user[3] < 0.1 %}
                            <div class="progress">
                                <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="0"
                                    aria-valuemin="0" aria-valuemax="100" style="width: 100%;">
                                    <span style="color: #0c0c0c;"> 无计划工时 </span>
                                </div>
                            </div>

                            {% else %}

                            <div class="progress">
                                <div class="progress-bar
                                {% if (100 * user[4] / user[3]).__int__() >= 100 %}
                                progress-bar-danger
                                {% else %}
                                progress-bar-success
                                {% endif %}
                                 
                                 " role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
                                    style="width: {{ (100 * user[4] / user[3]).__int__() }}%;">
                                    <span style="color: #0c0c0c;"> {{ (100 * user[4] / user[3]).__int__() }}% </span>
                                </div>
                            </div>

                            {% endif %}


                            {% else %}
                            <div class="progress">
                                <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0"
                                    aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
                                    <span style="color: #0c0c0c;"> 0% </span>
                                </div>
                            </div>
                            {% endif %}
                        </td>
                        <!-- 比例结束 -->
                        <td>
                            {% if user[4] %}
                            {{ user[4] }}
                            {% else %}
                            0
                            {% endif %}

                        </td>
                        <td>{{ user[3] }}</td>

                        <!-- 剩余工时 -->
                        <td>
                            {% if user[4] %}
                            {{  user[3] - user[4] }}
                            {% else %}
                            {{ user[3] }}
                            {% endif %}
                        </td>
                        {% if current_user.admin %}

                        <td>

                            <input type="text" data-project-org-id="{{ user[0] }}" data-project-id="{{ project_id }}"
                                style="width: 50px;">
                            <button class="planmanhour">修改</button>
                        </td>



                        <td>
                            <a
                                href="{{ url_for('bp_assess.modify_project_org', project_id=project_id, org_id=user[0]) }}">
                                {% if user[1] %}
                                取消负责人
                                {% else %}
                                设为负责人
                                {% endif %}
                            </a>
                        </td>
                        <td>
                            <a
                                href="{{ url_for('bp_assess.delete_project_org', project_id=project_id, org_id=user[0]) }}">删除</a>
                        </td>

                        {% endif %}

                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}